<template>
  <div>
    <el-dialog
      title="复制M单"
      @close="onClose"
      :visible.sync="CopyMasterOrderVisible"
    >
      <el-row :gutter="0">
        <el-form
          ref="params"
          :model="paramsData"
          :rules="rules"
          size="mini"
          label-width="120px"
          label-position="left"
        >
          <el-row :gutter="15">
            <el-col :span="3">
              <span>运单号</span>
            </el-col>
            <el-col :span="21">
              <el-input
                v-model="paramsData.waybillNo"
                size="mini"
                style="width: 200px"
                placeholder="请输入运单号"
              ></el-input>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="queryWaybillInfo"
                >搜索</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </el-row>
      <div style="height: 30px;"></div>
      <el-row :gutter="12">
        <el-col :span="6">
          <span style="margin-left: 50px">发件人</span>
          <el-divider></el-divider>
        </el-col>
        <el-col :span="6">
          <span>收件人</span>
          <el-divider></el-divider>
        </el-col>
        <el-col :span="6">
          <span>通知人</span>
          <el-divider></el-divider>
        </el-col>
        <el-col :span="6">
          <span>代理</span>
          <el-divider></el-divider>
        </el-col>
      </el-row>
      <el-row>
        <el-col
          :sm="24"
          :md="24"
          :lg="22"
          :xl="22"
          class="flex  align-center justify-start"
        >
          <div class="title-icon " style="margin-left: 50px">
            <span>M单 </span>
          </div>
          <span style="margin-left: 20px">M单号:</span
          ><span>{{ MInfo.masterNumber }}</span>
        </el-col>
      </el-row>
      <el-row :gutter="12">
        <el-col :span="2">
          <el-radio v-model="checkM" label="1">{{ "" }}</el-radio>
        </el-col>
        <el-col :span="4">
          <span style="margin-left: 30px">{{ MInfo.masterNumberSender }}</span>
        </el-col>
        <el-col :span="6">
          <span>{{ MInfo.masterNumberReceiver }}</span>
        </el-col>
        <el-col :span="6">
          <span>{{ MInfo.masterNumberNotifier }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ MInfo.masterNumberAgent }}</span>
        </el-col>
      </el-row>
      <div style="height: 100px;"></div>
      <div
        slot="footer"
        class="dialog-footer"
        v-loading.fullscreen.lock="fullscreenLoading"
      >
        <el-button size="mini" @click="CopyMasterOrderVisible = false"
          >取 消</el-button
        >
        <el-button size="mini" type="primary" @click="copyMaster"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { ajax } from "@/store/yg/common/utils";

export default {
  props: {
    waybillId: {
      type: Number,
      default: ""
    }
  },
  data() {
    return {
      show: "2",
      toUpDialog: false,
      CopyMasterOrderVisible: false,
      fullscreenLoading: false,
      waybillNo: null,
      checkM: null,
      restaurants: [],
      paramsData: {
        waybillNo: undefined
      },
      MInfo: {
        id: 0,
        waybillId: 0,
        masterNumber: "", // M单号：
        masterNumberSender: "", // M单号：发件人
        masterNumberReceiver: "", // M单号：收件人
        masterNumberNotifier: "", // M单号：通知人
        masterNumberAgent: "" // M单号：代理
      },
      rules: {
        waybillNo: [
          {
            required: true,
            message: "请输入单行文本运单号",
            trigger: "blur"
          }
        ]
      }
    };
  },
  mounted() {},
  methods: {
    queryWaybillInfo() {
      var param = {};
      const waybillNum = this.paramsData.waybillNo;
      param["waybillNo"] = waybillNum;
      const attrs = {
        class: "com.tofba.app.client.seaair.SeaAirExpressListClient"
      };
      this.fullscreenLoading = true;
      ajax("initDataPickUpData", param, attrs).then(
        res => {
          this.fullscreenLoading = false;
          if (res.code != 200) {
            this.$message.error(res.message);
          } else {
            if (null != res.data) {
              this.MInfo = res.data;
              console.log("查询获取的M单信息", this.MInfo);
            }
          }
        },
        error => {
          console.log(error);
        }
      );
    },
    close() {
      this.dialogTableVisible = false;
    },
    onClose() {
      this.$refs["params"].resetFields();
    },
    copyMaster() {
      if (this.checkM == null) {
        this.$message.error("请选择要复制的内容");
        return;
      }
      var param = this.MInfo;
      if ((this.param = null)) {
        this.$message.error("未查询到要复制的信息");
      } else {
        param["id"] = this.waybillId;
        param["nameDescription"] = null;
        param["masterNumber"] = null;
        param["soNumber"] = null;
        const attrs = {
          class: "com.tofba.app.client.seaair.SeaAirExpressListClient"
        };
        ajax("changeMInfo", param, attrs).then(
          res => {
            console.log(res);
            if (res.code != 200) {
              this.$message.error(res.message);
            } else {
              this.$message.success("保存成功");
              this.CopyMasterOrderVisible = false;
              window.location.reload(true);
            }
          },
          error => {
            console.log(error);
          }
        );
      }
    }
  }
};
</script>

<style scoped></style>
